﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace BlogDemo.Infrastructure
{
    /// <summary>
    /// DbContext interface
    /// </summary>
    public interface IDbContext : IDisposable
    {
        DatabaseFacade Database { get; }

        /// <summary>
        /// 获得实体集合
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        DbSet<TEntity> Set<TEntity>() where TEntity : class;

        EntityEntry<TEntity> Entry<TEntity>(TEntity entity) where TEntity : class;

        int SaveChanges();

        Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
 
        /// <summary> 
        /// Executes the given DDL/DML command against the database（无法应用于查询）. 
        /// </summary> 
        /// <param name="sql">The command string. </param> 
        /// <param name="parameters">The parameters to apply to the command string.</param> 
        /// <returns>返回影响的行数.</returns> 
        int ExecuteSqlCommand(string sql, params object[] parameters);
    }
}
